#include "SQLColumnReference.h"
#include "../../visitor/SQLASTVisitor.h"

SQLColumnReference::SQLColumnReference()
{
  columns = std::make_shared<std::list<SQLName_ptr>>();
}

void SQLColumnReference::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLColumnReference)))
  {
    acceptChild(visitor, this->getName());
  }
  visitor->endVisit(SharedObject(SQLColumnReference));
}

SQLName_ptr SQLColumnReference::getTable()
{
  return table;
}

void SQLColumnReference::setTable(SQLName_ptr table)
{
  this->table = table;
}

SQLName_list_ptr SQLColumnReference::getColumns()
{
  return columns;
}

void SQLColumnReference::setColumns(SQLName_list_ptr columns)
{
  this->columns = columns;
}

SQLObject_ptr SQLColumnReference::clone() {
    // SQLColumnReference* x = new SQLColumnReference();
    SQLObject_ptr clone_tmp = std::shared_ptr<SQLColumnReference>(new SQLColumnReference());
    std::shared_ptr<SQLColumnReference> x = std::dynamic_pointer_cast<SQLColumnReference>(clone_tmp);

    SQLConstraintImpl::cloneTo(std::dynamic_pointer_cast<SQLConstraintImpl>(x));

    if (table != NULL) {
        x->setTable(std::dynamic_pointer_cast<SQLName>(table->clone()));
    }

    for (SQLName_ptr column : *columns) {
        SQLName_ptr columnCloned = std::dynamic_pointer_cast<SQLName>(column->clone());
        columnCloned->setParent(x);
        x->columns->push_back(columnCloned);
    }

    x->referenceMatch = referenceMatch;
    x->onUpdate = onUpdate;
    x->onDelete = onDelete;

    return x;
}

SQLForeignKeyImpl_Match_ptr SQLColumnReference::getReferenceMatch()
{
  return referenceMatch;
}

void SQLColumnReference::setReferenceMatch(SQLForeignKeyImpl_Match_ptr referenceMatch)
{
  this->referenceMatch = referenceMatch;
}

SQLForeignKeyImpl_Option_ptr SQLColumnReference::getOnUpdate() {
    return onUpdate;
}

void SQLColumnReference::setOnUpdate(SQLForeignKeyImpl_Option_ptr onUpdate) {
    this->onUpdate = onUpdate;
}

SQLForeignKeyImpl_Option_ptr SQLColumnReference::getOnDelete() {
    return onDelete;
}

void SQLColumnReference::setOnDelete(SQLForeignKeyImpl_Option_ptr onDelete) {
    this->onDelete = onDelete;
}
